package io.renren.modules.archive.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import io.renren.modules.archive.dao.DictionaryDao;
import io.renren.modules.archive.entity.DictionaryEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.archive.dao.ArchiveAttachDao;
import io.renren.modules.archive.entity.ArchiveAttachEntity;
import io.renren.modules.archive.service.ArchiveAttachService;


@Service("archiveAttachService")
public class ArchiveAttachServiceImpl extends ServiceImpl<ArchiveAttachDao, ArchiveAttachEntity> implements ArchiveAttachService {
    @Autowired
    private ArchiveAttachDao archiveAttachDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //根据文件名称查询
        String username = (String)params.get("key");
        IPage<ArchiveAttachEntity> page = this.page(
                new Query<ArchiveAttachEntity>().getPage(params),
                new QueryWrapper<ArchiveAttachEntity>().like(StringUtils.isNotBlank(username),"file_name", username)
        );

        return new PageUtils(page);
    }
    @Override
    public List<ArchiveAttachEntity> queryListByName(String fileName) {

        QueryChainWrapper<ArchiveAttachEntity> wrapper = new QueryChainWrapper<>(archiveAttachDao);
        wrapper.eq(StringUtils.isNotBlank(fileName),"file_name", fileName);
        List<ArchiveAttachEntity> list= wrapper.list();

        return list;
    }

}